package com.pjj.userservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pjj.userservice.mapper.UserMapper;
import com.pjj.userservice.pojo.User;
import com.pjj.userservice.service.UserService;
import com.pjj.userservice.utils.TokenUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author 76004
 * @apiNote
 * @date 2023/1/16 16:50
 */


@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {


    @Autowired
    private UserService userService;

    @GetMapping("")
    public ModelAndView userLoggingPage(){
        return new ModelAndView("index");
    }


    @ApiOperation(value = "查询所有用户")
    @GetMapping("/selectAll")
    public Object selectAll(Integer pageNum,Integer pageSize){
        return userService.selectPage(pageNum,pageSize);
    }

    @ApiOperation(value = "插入用户")
    @PostMapping("/insertUser")
    public Object insertUser(@RequestBody User user){
        return userService.insertUser(user);
    }

    @ApiOperation(value = "更新用户")
    @PutMapping("/updateUser")
    public Object updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @ApiOperation(value = "按照id删除用户")
    @DeleteMapping("/delete")
    public Object deleteById(String userId){
        return userService.deleteById(userId);
    }

    @ApiOperation(value = "按照id选择用户")
    @GetMapping("/selectById")
    public Object selectById(String userId){
        return userService.selectById(userId);
    }

    @ApiOperation(value = "用户登录")
    @GetMapping("/login")
    public Object userLogin(String userId, String password){
        return userService.userLogin(userId,password);
    }

    @ApiOperation(value = "用户注册")
    @GetMapping("/register")
    public Object register(String userId,String password){
        return userService.userRegister(userId,password);
    }

    @ApiOperation(value = "按照用户id查询数量", notes = "查询用户是否存在")
    @GetMapping("/selectCountById")
    public Object selectCountById(String userId){
        return userService.selectCountById(userId);
    }

    @ApiOperation(value = "按照权限等级查询用户")
    @GetMapping("/selectByAuthority")
    public Object selectByAuthority(Integer authority,Integer pageNum,Integer pageSize){
        return userService.selectByAuthority(authority,pageNum,pageSize);
    }


    @GetMapping("/test")
    public Object test(String id){
        Map<String,Object>map = new HashMap<>();
        map.put("id",id+1);
        return map;
    }

}
